<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>清理LocalStorage</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <button type="button" onclick="clearData()">立即清理</button>
        <button type="button" onclick="showStorage()">刷新</button>
        <button type="button" onclick="testData()">测试</button>
        <div id="message"></div>
        <script>
            showStorage();
            function showStorage() {
                var storage = window.localStorage;
                var strout = '';
                for (var i = 0; i < storage.length; i++) {
                    //key(i)获得相应的键，再用getItem()方法获得对应的值
                    strout += storage.key(i) + " : " + storage.getItem(storage.key(i)) + "<br>";
                }
                document.getElementById('message').innerHTML = strout;
            }
            function clearData() {
                window.localStorage.clear();
                document.getElementById('message').innerHTML = '以上数据清理完成';
            }
            function testData() {
                window.localStorage.setItem('test', 'test123');
                showStorage();
            }
        </script>
    </body>
</html>
